﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.t201Menu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void t201_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            t201Mgr mgr = new t201Mgr();
            e.Total = int.Parse(mgr.GetRecordCount_t201(e.Parameters[t201_Filter.ParamPrefix]));
            IList<t201> list = mgr.FindAllByPage_t201(e.Start.ToString(), e.Limit.ToString(), e.Parameters[t201_Filter.ParamPrefix]);
            t201_MainStore.DataSource = list;
            t201_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            t201Mgr mgr = new t201Mgr();
            RowSelectionModel sm = t201_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                t201 _t201 = new t201();
                _t201.t201_00 = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_t201(_t201))
                {
                    log.Debug("t201中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            t201_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            t201Mgr mgr = new t201Mgr();
            t201 _t201 = new t201();
            if (Hid.Text.Length > 0)
                _t201 = mgr.FindById_t201(int.Parse(Hid.Text));
            
			_t201.t201_01 = Txtt201_01.Text.Trim();
			_t201.t201_02 = Txtt201_02.Text.Trim();
			_t201.t201_03 = Txtt201_03.Text.Trim();
			_t201.t201_04 = Txtt201_04.Text.Trim();
			_t201.t201_05 = Txtt201_05.Text.Trim();
			_t201.t201_06 = Txtt201_06.Text.Trim();
			_t201.t201_07 = Txtt201_07.Text.Trim();
			_t201.t201_08 = Txtt201_08.Text.Trim();
			_t201.t201_09 = Txtt201_09.Text.Trim();
			_t201.t201_10 = Txtt201_10.Text.Trim();
			_t201.t201_11 = Txtt201_11.Text.Trim();
			_t201.t201_12 = Txtt201_12.Text.Trim();
			_t201.t201_13 = Txtt201_13.Text.Trim();
			_t201.t201_14 = Txtt201_14.Text.Trim();
			_t201.t201_15 = Txtt201_15.Text.Trim();
			_t201.t201_16 = Txtt201_16.Text.Trim();
			_t201.t201_71 = Txtt201_71.Text.Trim();
			_t201.t201_72 = Txtt201_72.Text.Trim();
			_t201.t201_73 = Txtt201_73.Text.Trim();
			_t201.t201_74 = Txtt201_74.Text.Trim();
			_t201.t201_75 = Txtt201_75.Text.Trim();
			_t201.t201_76 = Txtt201_76.Text.Trim();
			_t201.t201_77 = Txtt201_77.Text.Trim();
			_t201.t201_78 = Txtt201_78.Text.Trim();
			_t201.t201_79 = Txtt201_79.Text.Trim();
			_t201.t201_80 = Txtt201_80.Text.Trim();
			_t201.t201_81 = Txtt201_81.Text.Trim();
			_t201.t201_82 = Txtt201_82.Text.Trim();
			_t201.t201_83 = Txtt201_83.Text.Trim();
			_t201.t201_84 = Txtt201_84.Text.Trim();
			_t201.t201_85 = Txtt201_85.Text.Trim();
			_t201.t201_86 = Txtt201_86.Text.Trim();
			_t201.t201_17 = Txtt201_17.Text.Trim();
			_t201.t201_70 = Txtt201_70.Text.Trim();
			_t201.t201_18 = Txtt201_18.Text.Trim();
			_t201.t201_19 = Txtt201_19.Text.Trim();
			_t201.t201_20 = Txtt201_20.Text.Trim();
			_t201.collection_time = Txtcollection_time.Text.Trim();

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_t201(_t201);
            else
                isok = mgr.Add_t201(_t201);
            if (isok)
            {
                t201_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("t201中执行了保存（插入或修改），并成功");
                t201_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}